﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Strongshell.Recoil.Core.Composition.Parsing.Handlers;

namespace Strongshell.Recoil.Core.Composition.Parsing
{
    public class DefaultExpressionParserFactory : IExpressionParserFactory
    {
        private readonly IObjectConfigurationRegistry objectConfigurationRegistry;

        public DefaultExpressionParserFactory(IObjectConfigurationRegistry objectConfigurationRegistry)
        {
            this.objectConfigurationRegistry = objectConfigurationRegistry;
        }

        public IExpressionParser Create()
        {
            var expressionParser = new ExpressionParser();

            expressionParser.NewExpressionHandler = new NewExpressionHandler(objectConfigurationRegistry, expressionParser);
            expressionParser.CompilingHandler = new CompilingHandler();
            expressionParser.CallExpressionHandler = new CallExpressionHandler(objectConfigurationRegistry,
                                                                               expressionParser,
                                                                               expressionParser.CompilingHandler);
            expressionParser.LambdaExpressionHandler = new LambdaExpressionHandler(expressionParser.CompilingHandler);
            expressionParser.ListInitExpressionHandler = new ListInitExpressionHandler(objectConfigurationRegistry, expressionParser,
                                                                                       expressionParser.CompilingHandler);
            expressionParser.MemberInitExpressionHandler = new MemberInitExpressionHandler(objectConfigurationRegistry, expressionParser);
            expressionParser.NewArrayInitExpressionHandler = new NewArrayInitExpressionHandler(objectConfigurationRegistry, expressionParser);
            expressionParser.NewExpressionHandler = new NewExpressionHandler(objectConfigurationRegistry, expressionParser);

            return expressionParser;
        }
    }
}
